<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="3600"> 
<title>Insert title here</title>
</head>
<body>
<script>

/*
12-25-2012 9:23:39 =1356427419
13-25-2012 9:23:39 =1359105819
14-26-2012 4:36:55 =1361853415
15-25-2012 9:23:39 =1364203419
16-26-2012 4:36:55 =1366951015
17-26-2012 4:36:55 =1369543015
18-26-2012 4:36:55 =1372221415
19-26-2012 4:36:55 =1374813415
20-26-2012 4:36:55 =1377491815
 */
var aStart=new Array();
var aEnd=new Array();
var bStart=new Array();
var bEnd=new Array();

aStart[0]=1356427419;//12
aEnd[0]= 1359105819;//13

aStart[1]=1361853415;//14
aEnd[1]=1364203419;//15

aStart[2]=1356427419;//12
aEnd[2]=1364203419;//15
/*
if((aStart <= bEnd) && (aEnd >= bStart)){
	alert("overlap");
}

*/
//alert(aStart.length);
/*
for(var i=0; i<aStart.length; i++){
	for(var j=0; j<i; j++){
		if((aStart[i] <= aEnd[j]) && (aEnd[j] >= aStart[1])){
			//alert("overlap");
		}else{
			//alert("not overlap");
		}	
	}
}
*/
//alert(aStart[1]);

</script>

SELECT


WDR.RESOURCE_CODE AS MACHINE_CODE , WDR.RESOURCE_DESCRIPTION AS MACHINE_NAME ,WE.WIP_ENTITY_NAME AS JOB ,
 
WOV.FIRST_UNIT_START_DATE 

AS START_DATE,WOV.LAST_UNIT_COMPLETION_DATE AS END_DATE, WOV.SCHEDULED_QUANTITY AS QUANTITY , 

WOV.QUANTITY_COMPLETED 

AS ACTSUAL, WOV.NEXT_OPERATION_SEQ_NUM, ML.MEANING, WOV.WIP_ENTITY_ID,
 
(

SELECT COUNT(*)
 


FROM WIP_ENTITIES WE2
 


INNER JOIN WIP_DISCRETE_JOBS_V WDJ2 ON WE2.WIP_ENTITY_ID = WDJ2.WIP_ENTITY_ID
 


INNER JOIN WIP_OPERATIONS_V WOV2 ON WE2.WIP_ENTITY_ID = WOV2.WIP_ENTITY_ID

 


INNER JOIN WIP_OPERATION_RESOURCES_V WOR2 ON WOV2.WIP_ENTITY_ID = WOR2.WIP_ENTITY_ID
 


INNER JOIN MFG_LOOKUPS ML2 ON WDJ2.STATUS_TYPE = ML2.LOOKUP_CODE

 


INNER JOIN WIP_DEPT_RESOURCES_V WDR2 ON WOR2.RESOURCE_ID = WDR2.RESOURCE_ID
 


WHERE ML2.LOOKUP_TYPE = 'WIP_JOB_STATUS' AND WDJ2.STATUS_TYPE IN (1, 3) 




AND WDR2.RESOURCE_TYPE = 'Machine' AND WDR2.SHARE_FROM_DEPARTMENT = WOV2.DEPARTMENT_CODE 



AND WOV2.OPERATION_SEQ_NUM =20
 


AND to_char(WOV2.FIRST_UNIT_START_DATE,'MM/DD/YYYY') between '12/01/2012' AND '12/26/2012'
 


AND WDR2.RESOURCE_CODE = WDR.RESOURCE_CODE
 


AND TO_CHAR(WOV2.FIRST_UNIT_START_DATE,'YYYY/MM/DD') = TO_CHAR(WOV.FIRST_UNIT_START_DATE,'YYYY/MM/DD')

 


AND (WOV.FIRST_UNIT_START_DATE < WOV2.LAST_UNIT_COMPLETION_DATE) 



AND (WOV.LAST_UNIT_COMPLETION_DATE > WOV2.FIRST_UNIT_START_DATE) ) AS OVERLAP_FLAG
 
FROM


 WIP_ENTITIES WE
 


INNER JOIN WIP_DISCRETE_JOBS_V WDJ
 


ON WE.WIP_ENTITY_ID = WDJ.WIP_ENTITY_ID
 


INNER JOIN WIP_OPERATIONS_V WOV
 


ON WE.WIP_ENTITY_ID = WOV.WIP_ENTITY_ID
 


INNER JOIN WIP_OPERATION_RESOURCES_V WOR
 


ON WOV.WIP_ENTITY_ID = WOR.WIP_ENTITY_ID
 


INNER JOIN MFG_LOOKUPS ML
 


ON WDJ.STATUS_TYPE = ML.LOOKUP_CODE
 


INNER JOIN WIP_DEPT_RESOURCES_V WDR
 


ON WOR.RESOURCE_ID = WDR.RESOURCE_ID
 
WHERE


ML.LOOKUP_TYPE = 'WIP_JOB_STATUS' AND WDJ.STATUS_TYPE IN (1, 3) 

AND


 WDR.RESOURCE_TYPE = 'Machine' AND WDR.SHARE_FROM_DEPARTMENT = WOV.DEPARTMENT_CODE 

AND


 WOV.OPERATION_SEQ_NUM =20
 
AND


 to_char(WOV.FIRST_UNIT_START_DATE,'MM/DD/YYYY') between '12/01/2012' AND '12/26/2012'

</body>
</html>